package com.ruoqing.admin.controller;

import com.ruoqing.admin.api.AuthService;
import com.ruoqing.core.constant.ModuleConstants;
import com.ruoqing.core.dto.BaseResponse;
import com.ruoqing.core.dto.auth.LoginUserDto;
import com.ruoqing.core.vo.auth.AuthResponseVo;
import com.ruoqing.core.web.BaseRestApi;
import com.ruoqing.log.annotation.BaseLog;
import com.ruoqing.log.enums.BusinessType;
import com.ruoqing.system.rest.Oauth2UserLogin;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
	* @author YaoXian
	* @title: AuthRestApi
	* @projectName ruoxi-blog
	* @description: 若兮微服务 - 鉴权控制器 - 统一认证与授权
	* @date 2020-12-18 0:02
	*/
@RestController
@RequestMapping(path = "/auth")
@Api(tags = "鉴权中心对外HTTP调用 - 统一认证与授权Rest接口")
public class AuthRestApi extends BaseRestApi {
		
		@Resource
		private AuthService authService;
		
		@Resource
		private Oauth2UserLogin oauth2UserLogin;
		
		/**
			* 分布式系统单点登录 - 管理统一登录接口
			* @param loginUserDto 登录信息体
			* @param authType 登录方式  1.账号密码登录 2.手机验证码登录
			* @return AuthResponseVo 鉴权响应交换对象
			*/
		@BaseLog(title = "管理员登录",module = ModuleConstants.APP_AUTH,businessType = BusinessType.GRANT)
		@ApiOperation(value = "管理员登录", httpMethod = "POST")
		@PostMapping(path = "/login/{authType}")
		public AuthResponseVo adminLogin(@RequestBody LoginUserDto loginUserDto, @PathVariable String authType){
				return authService.login(loginUserDto);
		}
		
		/**
			* 谷歌人机身份校验接口
			* @param googleToken 人机身份验证Token令牌
			* @return BaseResponse 统一响应对象
			*/
		@ApiOperation(value = "人机身份验证后台校验", httpMethod = "GET")
		@GetMapping(path = "/check")
		public BaseResponse googleCheck(String googleToken){
				return oauth2UserLogin.googleCheck(googleToken);
		}
}
